<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>state的简写方式</title>
    <!-- 引入 react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入 react-dom 用于支持操作DOM -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入 babel 用于将 jsx转为 js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
</head>
<body>
<div id="test"></div>

<script type="text/babel">
    class Weather extends React.Component {
        state = {
            isHot: false,
            wind: '微风'
        }
        // 自定义方法: 要用赋值语句+箭头函数
        changeWeather = () => {
            const isHot = this.state.isHot;
            this.setState({isHot: !isHot})
        }
        render() {
            const { isHot, wind} = this.state;
            return <h1 onClick={this.changeWeather}>今天天气很{isHot ? "炎热" : "凉爽"}, {wind}</h1>
        }
    }

    ReactDOM.render(<Weather />, document.getElementById("test"));

</script>
</body>
</html>